
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPainter>
#include<QPushButton>
#include<QPalette>
#include<QTimer>



MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //设置主场景
    //设置固定大小
    setFixedSize(340,560);
    //设置图标
    setWindowIcon(QIcon(":/picture/front.jpeg"));
    //设置标题
    setWindowTitle("哄阿尼亚开心");
    //退出按钮的实现
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });
    QPushButton* btn=new QPushButton(this);
    btn->move(this->width()*0.5-btn->width()*0.5,this->height()*0.8);
    btn->setText("start");
    QPalette palette;
    palette.setColor(QPalette::Button,QColor(245,212,217));
    btn->setAutoFillBackground(true);
    btn->setPalette(palette);
    btn->setFlat(true);
    //进入选择关卡的场景
    chooseScene=new ChooseLevelScene;
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
        chooseScene->hide();
        this->show();
    });
    connect(btn,&QPushButton::clicked,[=](){
        QTimer::singleShot(500,this,[=](){
            this->hide();
            chooseScene->show();
            //监听选择关卡的返回按钮的信号

        });

    });



}

void MainWindow::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/picture/background.jpg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}

MainWindow::~MainWindow()
{
    delete ui;
}